package controllers


import (
    "errors"
    "git.oschina.net/hfwb/tianqi.git/tq/model"
)

type User struct {
    base
}

func (this *User) CollectCity() {
    if !this.MustLogin() {
        return
    }
    cityCode, _ := this.GetInt("cityCode")
    if cityCode == 0 {
        this.Response(errors.New("cityCode is null"))
        return
    }
    var err error
    city := model.NewCity()
    city.InitByCode(cityCode)
    if city == nil {
        this.Response(errors.New("city non-existent"))
        return
    }
    m := model.NewStaffCollectCity()
    m.StaffId = this.staffId
    m.CityCode = cityCode
    if m.Id, err = m.DB.Insert(m); err != nil {
        this.Response(err)
    } else {
        this.Response(m)
    }
}

func (this *User) GetCity() {
    if !this.MustLogin() {
        return
    }
    list, err := model.NewStaffCollectCity().GetStaffCity(this.staffId)
    if err != nil {
        this.Response(err)
    } else {
        this.Response(list)
    }
}

func (this *User) DelCity() {
    if !this.MustLogin() {
        return
    }
    cityCode, _ := this.GetInt("cityCode")
    m := model.NewStaffCollectCity()
    err := m.DelStaffCity(this.staffId, cityCode)
    if err != nil {
        this.Response(err)
    } else {
        this.Response("success")
    }
}
